package com.mz.hotel.manage.serverlet.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.Session;

import org.apache.jasper.tagplugins.jstl.core.Out;

import com.mz.hotel.manage.service.loginServiceImpl;
import com.mz.hotel.until.ATTSystem;

public class adminServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName = request.getParameter("userName");
		String passWord = request.getParameter("passWord");

		loginServiceImpl loginservice = new loginServiceImpl();
		Map<String, Object> map = loginservice.login(userName, passWord);

		Object admin = map.get("admin");
		if (admin == null) {
			request.setAttribute("errMsg", map.get("msg"));
			request.setAttribute("userName", userName);
			request.getRequestDispatcher("/manage/login.jsp").forward(request, response);

		} else {
			request.getSession().setAttribute(ATTSystem.SESSION_ADMIN, admin);
			response.sendRedirect("/manage/main.jsp");
		}
	}

}
